//
//  CenterController.m
//  GuShiNews
//
//  Created by huachun on 2019/8/16.
//  Copyright © 2019 Jones. All rights reserved.
//

#import "CenterController.h"
#import "MyCenterCell.h"
#import "CenterModel.h"
#import "MyCenterViewModel.h"
#import "CenterAction.h"
#import "RootSuperAction.h"
#import "XueGuodeController.h"
#import "UserHomeController.h"
#import "MyLikeController.h"

@interface CenterController ()

@end

@implementation CenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setnavback];
    MyCenterViewModel *viewmodel = [[MyCenterViewModel alloc] init:@[]];
    self.Data_array = [NSMutableArray new];
    self.Data_array = [viewmodel.dataSource mutableCopy];
    
    self.navigationItem.title=@"个人中心";

    [self.view addSubview:self.TableView];
    self.TableView.separatorInset      = UIEdgeInsetsMake(0, 50, 0, 0);
    self.TableView.separatorStyle      = UITableViewCellSeparatorStyleSingleLineEtched;
    self.TableView.separatorColor      = [JonesClass stringTOColor:@"#e9e9e9"];
    self.TableView.backgroundColor = [JonesClass stringTOColor:@"#fbfbfb"];
    
    self.navigationItem.leftBarButtonItems=nil;
    
    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(car_init)
                                                 name:NEW_Center_Key
                                               object:nil];
}

- (void)car_init{
    [self.TableView reloadData];
}

- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self.TableView reloadData];
}

#pragma mark - UITableViewDataSource
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 20;
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return [self.Data_array count];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return [[self.Data_array objectAtIndex:section] count];
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    CenterModel *model = [[self.Data_array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    return model.Height;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    MyCenterCell *cell = [MyCenterCell cellForTableView:tableView cellForRowAtIndexPath:indexPath];
    cell.Model = [[self.Data_array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    UserModel *userlin = [UserModel info];
    CenterModel *model = [[self.Data_array objectAtIndex:indexPath.section] objectAtIndex:indexPath.row];
    if (indexPath.section==0) {
        if (!userlin.userid) {
            [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
        }else{
            [CenterAction Actiontodone:JonesGOTO_CenterData view:self dictionary:@{}];
        }
    }else{
        if ([model.Type isEqualToString:@"30"]) {
            [CenterAction Actiontodone:JonesGOTO_CenterSetting view:self dictionary:@{}];
        }
        else if ([model.Type isEqualToString:@"0"]){
            [CenterAction Actiontodone:JonesGOTO_CenterLike view:self dictionary:@{}];
        }
        else if ([model.Type isEqualToString:@"1"]){
            [CenterAction Actiontodone:JonesGOTO_CenterHate view:self dictionary:@{}];
        }
        else if ([model.Type isEqualToString:@"6"]){
            [CenterAction Actiontodone:JonesGOTO_CenterHistry view:self dictionary:@{}];
        }
        else if ([model.Type isEqualToString:@"5"]){
            if (!userlin.userid) {
                [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
                return;
            }
            [CenterAction Actiontodone:JonesGOTO_CenterComment view:self dictionary:@{@"type":@"1"}];
        }
        else if ([model.Type isEqualToString:@"8"]){
            if (!userlin.userid) {
                [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
                return;
            }
            [CenterAction Actiontodone:JonesGOTO_CenterComment view:self dictionary:@{@"type":@"0"}];
        }
        else if ([model.Type isEqualToString:@"29"]){
            XueGuodeController *xuexi = [XueGuodeController new];
            xuexi.hidesBottomBarWhenPushed = YES;
            [self.navigationController pushViewController:xuexi animated:YES];
        }
        else if ([model.Type isEqualToString:@"15"]){
            if (!userlin.userid) {
                [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
                return;
            }
            MyLikeController *liekvc = [MyLikeController new];
            liekvc.hidesBottomBarWhenPushed = YES;
            liekvc.Here_type = 0;
            [self.navigationController pushViewController:liekvc animated:YES];
        }else if ([model.Type isEqualToString:@"16"]){
            if (!userlin.userid) {
                [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
                return;
            }
            MyLikeController *liekvc = [MyLikeController new];
            liekvc.hidesBottomBarWhenPushed = YES;
            liekvc.Here_type = 1;
            [self.navigationController pushViewController:liekvc animated:YES];
        }else if ([model.Type isEqualToString:@"17"]){
            if (!userlin.userid) {
                [RootSuperAction Actiontodone:JonesGOTO_Login view:self dictionary:@{}];
                return;
            }
            UserHomeController *uwerdfsf = [UserHomeController new];
            uwerdfsf.hidesBottomBarWhenPushed = YES;
            uwerdfsf.Model = userlin;
            [self.navigationController pushViewController:uwerdfsf animated:YES];
        }
    }
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}

@end
